package hu;

import java.util.*;

public class hu98 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        String[] mingling = input.split(";");
        List<String> re = new ArrayList<>();
        int[][] goods = new int[6][3];
        int[][] moneys = new int[4][2];
        goods[0][1] = 2;
        goods[1][1] = 3;
        goods[2][1] = 4;
        goods[3][1] = 5;
        goods[4][1] = 8;
        goods[5][1] = 6;
        moneys[0][0] = 1;
        moneys[1][0] = 2;
        moneys[2][0] = 5;
        moneys[3][0] = 10;
        int sum = 0;
        int num_goods = 0;
        int tou = 0;
        for (int i = 0; i < mingling.length; i++) {
            String[] oneMingling = mingling[i].split(" ");
            //初始化
            if(oneMingling[0].equals("r")){
                sum = 0;
                num_goods = 0;
                String[] good = oneMingling[1].split("-");
                String[] money = oneMingling[2].split("-");
                for (int j = 0; j < good.length; j++) {
                    goods[j][0] = j + 1;
                    goods[j][2] = Integer.parseInt(good[j]);
                    num_goods += goods[j][2];
                }
                for (int k = 0; k < money.length; k++) {
                    moneys[k][1] = Integer.parseInt(money[k]);
                    sum += moneys[k][0] * moneys[k][1];
                }
                re.add("S001:Initialization is successful");
            }
            //投币
            else if(oneMingling[0].equals("p")){
                int sum1_2 = 0;
                for (int j = 0; j < 2; j++) {
                    sum1_2 += moneys[j][0] * moneys[j][1];
                }
                if(!(oneMingling[1].equals("1") || oneMingling[1].equals("2") ||
                        oneMingling[1].equals("5") || oneMingling[1].equals("10"))){
                    re.add("E002:Denomination error");
                }
                else if((oneMingling[1].equals("5") && sum1_2 < 5) || (oneMingling[1].equals("10") && sum1_2 < 10)){
                    re.add("E003:Change is not enough, pay fail");
                }
                else if(num_goods == 0){
                    re.add("E005:All the goods sold out");
                }
                else{
                    if(Integer.parseInt(oneMingling[1]) == 1)
                        moneys[0][1]++;
                    if(Integer.parseInt(oneMingling[1]) == 2)
                        moneys[1][1]++;
                    if(Integer.parseInt(oneMingling[1]) == 5)
                        moneys[2][1]++;
                    if(Integer.parseInt(oneMingling[1]) == 10)
                        moneys[3][1]++;
                    tou += Integer.parseInt(oneMingling[1]);
                    re.add("S002:Pay success,balance=" + tou);
                }
            }
            //购买
            else if(oneMingling[0].equals("b")){
                if(oneMingling[1].charAt(0) != 'A' || oneMingling[1].charAt(1) > '6'
                        || oneMingling[1].charAt(1) < '1'){
                    re.add("E006:Goods does not exist");
                }
                else if(goods[oneMingling[1].charAt(1) - '1'][2] == 0){
                    re.add("E007:The goods sold out");
                }
                else if(tou < goods[oneMingling[1].charAt(1) - '1'][1]){
                    re.add("E008:Lack of balance");
                }
                else{
                    tou -= goods[oneMingling[1].charAt(1) - '1'][1];
                    re.add("S003:Buy success,balance=" + tou);
                }
            }
            //退币
            else if(oneMingling[0].equals("c")){
                if(tou == 0){
                    re.add("E009:Work failure");
                }
                else{
                    int[] drawBack = new int[4];
                    if(tou / 10 != 0 && moneys[3][1] >= tou / 10){
                        drawBack[3] = tou / 10;
                        moneys[3][1] -= tou /10;
                        tou = tou % 10;
                    }
                    if(tou / 5 != 0 && moneys[2][1] >= tou / 5){
                        drawBack[2] = tou / 5;
                        moneys[2][1] -= tou /5;
                        tou = tou % 5;
                    }
                    if(tou / 2 != 0 && moneys[1][1] >= tou / 2){
                        drawBack[1] = tou / 2;
                        moneys[1][1] -= tou /2;
                        tou = tou % 2;
                    }
                    if(tou != 0 && moneys[0][1] >= tou){
                        drawBack[0] = tou;
                        moneys[0][1] -= tou;
                    }
                    tou = 0;
                    for (int j = 0; j < moneys.length; j++) {
                        re.add(moneys[j][0] + " yuan coin number=" + drawBack[j]);
                    }
                }
            }
            //查询
            else if(oneMingling[0].equals("q")){
                if(oneMingling[1].equals("0")){
                    List<List<String>> G = new ArrayList<>();
                    for (int j = 0; j < goods.length; j++) {
                        List<String> l1 = new ArrayList<>();
                        l1.add("A" + goods[j][0]);
                        l1.add(goods[j][1] + "");
                        l1.add(goods[j][2] + "");
                        G.add(l1);
                    }
                    Collections.sort(G, (a,b) -> {
                        return Integer.parseInt(b.get(2)) - Integer.parseInt(a.get(2));
                    });
                    for (int j = 0; j < G.size(); j++) {
                        re.add(G.get(j).get(0) + " " + G.get(j).get(1) + " " + G.get(j).get(2));
                    }
                }
                else if(oneMingling[1].equals("1")){
                    for (int j = 0; j < moneys.length; j++) {
                        re.add(moneys[j][0] + " yuan coin number=" + moneys[j][1]);
                    }
                }
                else{
                    re.add("E010:Parameter error");
                }
            }
            else {
                re.add("E010:Parameter error");
            }
        }
        for (String s : re) {
            System.out.println(s);
        }
    }
}
